<?php

class CMS_TreeManager extends CMS_Db_Table_Abstract_Xml
{
    protected $_name  = 'documents';
    protected $_primary  = 'id';
    protected $toto  = 'toto';
	
	
	protected function _build ($path = "/"){
		$sql = $this->select()->where("document_directory = '$path'")->order($this->sqlOrderByInstruction);
		$res = $this->fetchAll($sql);
		foreach($res->toArray() as $file){
			switch($file["directory_status"]){
				case 0:
					
					$this->xmlWriter->startElement('file');
					foreach($file as $prop=>$val){
						$p = $this->cleanNameSpace($prop);
						@$this->xmlWriter->writeAttribute($p, $val);
					}	
					$this->xmlWriter->endElement();
					break;
				case 1:
					$this->xmlWriter->startElement('folder');
					foreach($file as $prop=>$val){
						$p = $this->cleanNameSpace($prop);
						@$this->xmlWriter->writeAttribute($p, $val);		
					}	
					//$this->xmlWriter->startElement('file');
					$this->_build($file["document_path"]);
					//$this->xmlWriter->endElement();
					$this->xmlWriter->endElement();
					break;
			}
		}
	}
	
}
